package com.hj.saapp.control.activity;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.TextView;

import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.hj.saapp.R;
import com.hj.saapp.bean.MyUserInfoBean;
import com.hj.saapp.bean.MyUserInfoDataBean;
import com.hj.saapp.common.manager.NetworkManager;
import com.hj.saapp.common.utils.HttpHelper;
import com.hj.saapp.control.activity.base.BaseActivity;
import com.hj.saapp.control.adapter.MyUserInfoAdapter;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

import lib.hj.com.commonlib.bean.BaseBean;

public class MyUserInfoActivity extends BaseActivity implements View.OnClickListener {
    private EditText JYBHEtMsg;
    private EditText YHMEtMsg;
    private EditText BMBHEtMsg;
    private Button submitBtn;
    private TextView textView;
    private MyUserInfoDataBean myUserInfoDataBean;
    private MyUserInfoBean myUserInfoBean;

    @Override
    public int getLayoutByid() {
        return R.layout.activity_my_user_info;
    }
    @Override
    public int getTitleById() {
        return R.string.user_info_title;
    }

    @Override
    public void initView() {
        JYBHEtMsg = (EditText) findViewById(R.id.JYBHEt_msg);
        YHMEtMsg = (EditText) findViewById(R.id.YHMEt_msg);
        BMBHEtMsg = (EditText) findViewById(R.id.BMBHEt_msg);
        submitBtn = (Button) findViewById(R.id.submit_btn);
        textView= (TextView) findViewById(R.id.textView);
//        myList = (ListView) findViewById(R.id.mylist);
    }

    @Override
    public void initListener() {
        submitBtn.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        String jybh = JYBHEtMsg.getText().toString();
        String yhm = YHMEtMsg.getText().toString();
        if (TextUtils.isEmpty(jybh) && TextUtils.isEmpty(yhm)) {
            showMessageEmpty("警员编号和用户名");
            return;
        }
        if (NetworkManager.getNetworkManager().isNetworkConnected()) {
            prepareLoadData();
        }
    }

    @Override
    public void getHttpData() throws Exception {
        JsonObject log = new JsonObject();
        log.addProperty("USER_ID", "admin");
        log.addProperty("USER_NAME", "admin");
        log.addProperty("DEPARTMENTCODE", "4400000000");
        JsonObject user = new JsonObject();
        user.addProperty("USER_ID", JYBHEtMsg.getText().toString());
        json.add("log", log);
        json.add("user", user);
        HttpHelper.login(this, json);
    }

    @Override
    public void onSuccess(BaseBean paramObject) {
        super.onSuccess(paramObject);
        Log.i("paramObject", paramObject.toString());
                textView.setText(paramObject+"");

    }

    List<MyUserInfoBean> list;

    private MyUserInfoDataBean jsonCheckout(String result1) {
        list = new ArrayList();
        try {
            JSONObject jsonObject =new JSONObject(result1);
            JSONArray dataArray = jsonObject.getJSONArray("DATA");
            for (int i = 0; i < dataArray.length(); i++) {
                JSONObject object = dataArray.getJSONObject(i);
                String yhm = object.getString("yhm");
                String dwmc = object.getString("dwmc");
                String dwdm = object.getString("dwdm");
                String js = object.getString("js");
                myUserInfoBean = new MyUserInfoBean(yhm, dwmc, dwdm, js);
                list.add(myUserInfoBean);
                myUserInfoDataBean = new MyUserInfoDataBean(list);
            }
        } catch (JSONException e) {
            e.printStackTrace();

        }
        return myUserInfoDataBean;
    }

    @Override
    public void onFailure(int paramInt, String paramString) {
        super.onFailure(paramInt, paramString);
        String data=paramString;
        textView.setText(data);
    }

}
